package cn.doitedu.utils;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.flink.table.functions.ScalarFunction;

import java.text.ParseException;
import java.util.Date;

public class TimeTruncUDF2 extends ScalarFunction {

    public String eval(Long originTime, int interval){
        String truncated = null;
        try {
            Long time  = (originTime / (interval*60*1000L))*(interval*60*1000L);
            truncated = DateFormatUtils.format(time, "yyyy-MM-dd HH:mm:ss");

        } catch (Exception e){
            e.printStackTrace();
        }


        return truncated;
    }


}
